package club.kingyin.kyblog.controller;

import club.kingyin.kyblog.core.IP;
import club.kingyin.kyblog.core.business.dao.Doc;
import club.kingyin.kyblog.core.business.dto.ResultUtil;
import club.kingyin.kyblog.core.business.service.DocService;
import club.kingyin.kyblog.core.business.vo.admin.TypeCount;
import club.kingyin.kyblog.core.extend.IPSetPostProcessor;
import club.kingyin.kyblog.core.utils.log.LogConsole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @author ：kingyin
 * @date ：创建于 2021/8/29 5:18 下午
 * @description ：
 * @modified By：
 * @version: 1.0.0
 */
@IP
@RestController
@RequestMapping("/data")
public class DataController {

    @Autowired
    private DocService docService;

    @LogConsole(module = "获得热点文章", operator = "九命可", sources = IPSetPostProcessor.class)
    @GetMapping("/bar")
    public ResultUtil bar() {
        Set<Doc> barChart = docService.getBarChart();
        if (barChart == null) {
            return ResultUtil.fail("加载失败");
        }
        return ResultUtil.success(barChart);
    }

    @LogConsole(module = "文章分类统计", operator = "九命可", sources = IPSetPostProcessor.class)
    @GetMapping("/pie")
    public ResultUtil pie() {
        Set<TypeCount> pieChart = docService.getPieChart();
        if (pieChart == null) {
            return ResultUtil.fail("加载失败");
        }
        return ResultUtil.success(pieChart);
    }

    @LogConsole(module = "文章及评论统计", operator = "九命可", sources = IPSetPostProcessor.class)
    @GetMapping("/panel")
    public ResultUtil panel() {
        Integer[] panelGroup = docService.getPanelGroup();
        if (panelGroup == null) {
            return ResultUtil.fail("加载失败");
        }
        return ResultUtil.success(panelGroup);
    }
}
